package com.gr.yupao.once;

import com.gr.yupao.mapper.UserMapper;
import com.gr.yupao.model.domain.User;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;


@Component
public class InsertUsers {

    @Resource
    private UserMapper userMapper;

    private boolean hasRun = false;

    /**
     * 批量插入用户
     */
//    @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
    public void doInsertUsers() {
        if (!hasRun) {
            StopWatch stopWatch = new StopWatch();
            stopWatch.start();
            final int INSERT_NUM = 1000;
            for (int i = 0; i < INSERT_NUM; i ++) {
                User user = new User();
                user.setUsername("假用户");
                user.setUserAccount("fakeuser");
                user.setAvatarUrl("https://app6882.acapp.acwing.com.cn/api/uploads/1733235689940_%25E6%259C%25AC%25E6%259C%25BA%25E7%2585%25A7%25E7%2589%25871665906279975.png");
                user.setGender(0);
                user.setUserPassword("12345678");
                user.setPhone("52698711");
                user.setEmail("123@qq.com");
                user.setUserStatus(0);
                user.setUserRole(0);
                user.setPlanetCode("1111");
                user.setTags("[]");
                user.setProfile("hhh");
                userMapper.insert(user);
            }
            stopWatch.stop();
            long totalTimeMillis = stopWatch.getTotalTimeMillis();
            System.out.println(totalTimeMillis);
            hasRun = true;
        }
    }
}
